home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr29 / memsize.zip / ITEMS.CPP < prev    next >
Text File  |  1995-01-04  |  16KB  |  779 lines

  1. /****************************************************************** ITEMS.CPP
  2.  *                                                                          *
  3.  *                     Display Item Class Functions                         *
  4.  *                                                                          *
  5.  ****************************************************************************/
  6.  
  7. #define INCL_BASE
  8. #define INCL_PM
  9. #include <os2.h>
  10.  
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14.  
  15. #include "debug.h"
  16. #include "support.h"
  17. #include "restring.h"
  18.  
  19. #include "items.h"
  20.  
  21.  
  22. VOID Item::Paint
  23. (
  24.   HPS hPS,
  25.   RECTL &Rectangle,
  26.   COLOR TextColor,
  27.   COLOR BackColor,
  28.   PSZ Text,
  29.   ULONG NewValue
  30. )
  31. {
  32.   WinDrawText ( hPS, strlen(PCHAR(Text)), Text, &Rectangle,
  33.     TextColor, BackColor, DT_RIGHT | DT_BOTTOM | DT_ERASERECT ) ;
  34.  
  35.   WinDrawText ( hPS, strlen(PCHAR(Label)), Label, &Rectangle,
  36.     TextColor, BackColor, DT_LEFT | DT_BOTTOM ) ;
  37.  
  38.   Value = NewValue ;
  39. }
  40.  
  41.  
  42. ULONG Clock::NewValue ( void )
  43. {
  44.   DATETIME DateTime ;
  45.   DosGetDateTime ( &DateTime ) ;
  46.  
  47.   ULONG Time ;
  48.   Time  = DateTime.weekday ;
  49.   Time *= 100 ;
  50.   Time += DateTime.month ;
  51.   Time *= 100 ;
  52.   Time += DateTime.day ;
  53.   Time *= 100 ;
  54.   Time += DateTime.hours ;
  55.   Time *= 100 ;
  56.   Time += DateTime.minutes ;
  57.  
  58.   return ( Time ) ;
  59. }
  60.  
  61.  
  62. VOID Clock::Repaint
  63. (
  64.   HPS hPS,
  65.   RECTL &Rectangle,
  66.   COLOR TextColor,
  67.   COLOR BackColor,
  68.   BOOL Mandatory
  69. )
  70. {
  71.   ULONG Time = NewValue ( ) ;
  72.  
  73.   if ( Mandatory || ( Time != Value ) )
  74.   {
  75.     BYTE Text [100] ;
  76.     ULONG Dow    = ( Time % 1000000000L ) / 100000000L ;
  77.     ULONG Month  = ( Time % 100000000L )  / 1000000L ;
  78.     ULONG Day    = ( Time % 1000000L )    / 10000L ;
  79.     ULONG Hour   = ( Time % 10000L )      / 100L ;
  80.     ULONG Minute = ( Time % 100L ) ;
  81.  
  82.     sprintf ( PCHAR(Text), "%0.3s, ", PSZ(*DaysOfWeek) + Dow*3 ) ;
  83.  
  84.     switch ( CountryInfo.fsDateFmt )
  85.     {
  86.       case DATEFMT_DD_MM_YY:
  87.         sprintf ( PCHAR(Text)+strlen(PCHAR(Text)), "%02lu%s%02lu ",
  88.           Day, CountryInfo.szDateSeparator, Month ) ;
  89.         break ;
  90.  
  91.       case DATEFMT_YY_MM_DD:
  92.       case DATEFMT_MM_DD_YY:
  93.       default:
  94.         sprintf ( PCHAR(Text)+strlen(PCHAR(Text)), "%02lu%s%02lu ",
  95.           Month, CountryInfo.szDateSeparator, Day ) ;
  96.         break ;
  97.     }
  98.  
  99.     if ( CountryInfo.fsTimeFmt )
  100.     {
  101.       sprintf ( PCHAR(Text)+strlen(PCHAR(Text)), "%02lu%s%02lu",
  102.         Hour,
  103.         CountryInfo.szTimeSeparator,
  104.         Minute ) ;
  105.     }
  106.     else
  107.     {
  108.       PCHAR AmPm ;
  109.  
  110.       if ( Hour )
  111.       {
  112.         if ( Hour < 12 )
  113.         {
  114.           AmPm = "a" ;
  115.         }
  116.         else if ( Hour == 12 )
  117.         {
  118.           if ( Minute )
  119.             AmPm = "p" ;
  120.           else
  121.             AmPm = "a" ;
  122.         }
  123.         else if ( Hour > 12 )
  124.         {
  125.           Hour -= 12 ;
  126.           AmPm = "p" ;
  127.         }
  128.       }
  129.       else
  130.       {
  131.         Hour = 12 ;
  132.         if ( Minute )
  133.           AmPm = "a" ;
  134.         else
  135.           AmPm = "p" ;
  136.       }
  137.       sprintf ( PCHAR(Text)+strlen(PCHAR(Text)), "%02lu%s%02lu%s",
  138.         Hour, CountryInfo.szTimeSeparator, Minute, AmPm ) ;
  139.     }
  140.  
  141.     Paint ( hPS, Rectangle, TextColor, BackColor, Text, Time ) ;
  142.   }
  143. }
  144.  
  145.  
  146. ULONG ElapsedTime::NewValue ( void )
  147. {
  148.   ULONG Milliseconds ;
  149.   DosQuerySysInfo ( QSV_MS_COUNT, QSV_MS_COUNT, &Milliseconds, sizeof(Milliseconds) ) ;
  150.   return ( Milliseconds / 60000L ) ;
  151. }
  152.  
  153.  
  154. VOID ElapsedTime::Repaint
  155. (
  156.   HPS hPS,
  157.   RECTL &Rectangle,
  158.   COLOR TextColor,
  159.   COLOR BackColor,
  160.   BOOL Mandatory
  161. )
  162. {
  163.   ULONG Time = NewValue ( ) ;
  164.  
  165.   if ( Mandatory || ( Time != Value ) )
  166.   {
  167.     BYTE Text [100] ;
  168.  
  169.     memset ( Text, 0, sizeof(Text) ) ;
  170.  
  171.     ULONG NumberOfDays = Time / ( 60L * 24L ) ;
  172.  
  173.     if ( NumberOfDays )
  174.     {
  175.       sprintf ( PCHAR(Text), "%lu %s, ",
  176.         NumberOfDays, NumberOfDays > 1 ? PSZ(*Days) : PSZ(*Day) ) ;
  177.     }
  178.  
  179.     ULONG Minutes = Time % ( 60L * 24L ) ;
  180.  
  181.     sprintf ( PCHAR(Text+strlen(PCHAR(Text))), "%lu%s%02lu",
  182.       Minutes/60, CountryInfo.szTimeSeparator, Minutes%60 ) ;
  183.  
  184.     Paint ( hPS, Rectangle, TextColor, BackColor, Text, Time ) ;
  185.   }
  186. }
  187.  
  188.  
  189. APIRET16 APIENTRY16 Dos16MemAvail ( PULONG pulAvailMem ) ;
  190.  
  191. ULONG MemoryFree::NewValue ( void )
  192. {
  193.   ULONG Space ;
  194.   Dos16MemAvail ( &Space ) ;
  195.   return ( Space ) ;
  196. }
  197.  
  198.  
  199. VOID MemoryFree::Repaint
  200. (
  201.   HPS hPS,
  202.   RECTL &Rectangle,
  203.   COLOR TextColor,
  204.   COLOR BackColor,
  205.   BOOL Mandatory
  206. )
  207. {
  208.   ULONG Size = NewValue ( ) ;
  209.  
  210.   if ( Mandatory || ( Size != Value ) )
  211.   {
  212.     BYTE Text [100] ;
  213.  
  214.     if ( Size < 0x80000 )
  215.       sprintf ( (PCHAR)Text, "%lu", Size ) ;
  216.     else
  217.       sprintf ( (PCHAR)Text, "%lu", (Size+512)/1024 ) ;
  218.  
  219.     {
  220.       PBYTE p1, p2 ;
  221.       BYTE Work[100] ;
  222.  
  223.       p1 = Text ;
  224.       p2 = Work ;
  225.       while ( *p1 )
  226.       {
  227.         *p2 = *p1 ;
  228.         p1 ++ ;
  229.         p2 ++ ;
  230.         if ( *p1 )
  231.         {
  232.           if ( strlen((PCHAR)p1) % 3 == 0 )
  233.           {
  234.             *p2 = CountryInfo.szThousandsSeparator [0] ;
  235.             p2 ++ ;
  236.           }
  237.         }
  238.       }
  239.       *p2 = 0 ;
  240.       strcpy ( (PCHAR)Text, (PCHAR)Work ) ;
  241.     }
  242.  
  243.     Text[strlen(PCHAR(Text))+1] = 0 ;
  244.     if ( Size < 0x80000 )
  245.       Text[strlen((PCHAR)Text)] = ' ' ;
  246.     else
  247.       Text[strlen((PCHAR)Text)] = 'K' ;
  248.  
  249.     Paint ( hPS, Rectangle, TextColor, BackColor, Text, Size ) ;
  250.   }
  251. }
  252.  
  253.  
  254. ULONG SwapSize::NewValue ( void )
  255. {
  256.   char Path [_MAX_PATH+1] ;
  257.  
  258.   strcpy ( Path, (PCHAR)SwapPath ) ;
  259.  
  260.   if ( Path[strlen(Path)-1] != '\\' )
  261.   {
  262.     strcat ( Path, "\\" ) ;
  263.   }
  264.  
  265.   strcat ( Path, "SWAPPER.DAT" ) ;
  266.  
  267.   ULONG SwapSize = 0 ;
  268.   FILESTATUS3 Status ;
  269.   if ( DosQueryPathInfo ( (PSZ)Path, FIL_STANDARD, &Status, sizeof(Status) ) == 0 )
  270.   {
  271.     SwapSize = Status.cbFileAlloc ;
  272.   }
  273.  
  274.   return ( SwapSize ) ;
  275. }
  276.  
  277.  
  278. VOID SwapSize::Repaint
  279. (
  280.   HPS hPS,
  281.   RECTL &Rectangle,
  282.   COLOR TextColor,
  283.   COLOR BackColor,
  284.   BOOL Mandatory
  285. )
  286. {
  287.   ULONG Size = NewValue ( ) ;
  288.  
  289.   if ( Mandatory || ( Size != Value ) )
  290.   {
  291.     BYTE Text [100] ;
  292.  
  293.     if ( Size < 0x80000 )
  294.       sprintf ( (PCHAR)Text, "%lu", Size ) ;
  295.     else
  296.       sprintf ( (PCHAR)Text, "%lu", (Size+512)/1024 ) ;
  297.  
  298.     {
  299.       PBYTE p1, p2 ;
  300.       BYTE Work[100] ;
  301.  
  302.       p1 = Text ;
  303.       p2 = Work ;
  304.       while ( *p1 )
  305.       {
  306.         *p2 = *p1 ;
  307.         p1 ++ ;
  308.         p2 ++ ;
  309.         if ( *p1 )
  310.         {
  311.           if ( strlen((PCHAR)p1) % 3 == 0 )
  312.           {
  313.             *p2 = CountryInfo.szThousandsSeparator [0] ;
  314.             p2 ++ ;
  315.           }
  316.         }
  317.       }
  318.       *p2 = 0 ;
  319.       strcpy ( (PCHAR)Text, (PCHAR)Work ) ;
  320.     }
  321.  
  322.     Text[strlen(PCHAR(Text))+1] = 0 ;
  323.     if ( Size < 0x80000 )
  324.       Text[strlen((PCHAR)Text)] = ' ' ;
  325.     else
  326.       Text[strlen((PCHAR)Text)] = 'K' ;
  327.  
  328.     Paint ( hPS, Rectangle, TextColor, BackColor, Text, Size ) ;
  329.   }
  330. }
  331.  
  332.  
  333. ULONG SwapFree::NewValue ( void )
  334. {
  335.   char Path [_MAX_PATH+1] ;
  336.  
  337.   strcpy ( Path, (PCHAR)SwapPath ) ;
  338.   strcat ( Path, "\\SWAPPER.DAT" ) ;
  339.  
  340.   ULONG SwapFree = 0 ;
  341.   if ( Path[0] )
  342.   {
  343.     DosError ( FERR_DISABLEHARDERR ) ;
  344.     FSALLOCATE Allocation ;
  345.     DosQueryFSInfo ( Path[0]-'A'+1, FSIL_ALLOC,
  346.       (PBYTE)&Allocation, sizeof(Allocation) ) ;
  347.     DosError ( FERR_ENABLEHARDERR ) ;
  348.  
  349.     SwapFree = Allocation.cUnitAvail*Allocation.cSectorUnit*Allocation.cbSector ;
  350.   }
  351.  
  352.   if ( SwapFree < ULONG(MinFree*1024L) )
  353.     return ( 0L ) ;
  354.   else
  355.     return ( SwapFree - ULONG(MinFree*1024L) ) ;
  356. }
  357.  
  358.  
  359. VOID SwapFree::Repaint
  360. (
  361.   HPS hPS,
  362.   RECTL &Rectangle,
  363.   COLOR TextColor,
  364.   COLOR BackColor,
  365.   BOOL Mandatory
  366. )
  367. {
  368.   ULONG Size = NewValue ( ) ;
  369.  
  370.   if ( Mandatory || ( Size != Value ) )
  371.   {
  372.     BYTE Text [100] ;
  373.  
  374.     if ( Size < 0x80000 )
  375.       sprintf ( (PCHAR)Text, "%lu", Size ) ;
  376.     else
  377.       sprintf ( (PCHAR)Text, "%lu", (Size+512)/1024 ) ;
  378.  
  379.     {
  380.       PBYTE p1, p2 ;
  381.       BYTE Work[100] ;
  382.  
  383.       p1 = Text ;
  384.       p2 = Work ;
  385.       while ( *p1 )
  386.       {
  387.         *p2 = *p1 ;
  388.         p1 ++ ;
  389.         p2 ++ ;
  390.         if ( *p1 )
  391.         {
  392.           if ( strlen((PCHAR)p1) % 3 == 0 )
  393.           {
  394.             *p2 = CountryInfo.szThousandsSeparator [0] ;
  395.             p2 ++ ;
  396.           }
  397.         }
  398.       }
  399.       *p2 = 0 ;
  400.       strcpy ( (PCHAR)Text, (PCHAR)Work ) ;
  401.     }
  402.  
  403.     Text[strlen(PCHAR(Text))+1] = 0 ;
  404.     if ( Size < 0x80000 )
  405.       Text[strlen((PCHAR)Text)] = ' ' ;
  406.     else
  407.       Text[strlen((PCHAR)Text)] = 'K' ;
  408.  
  409.     Paint ( hPS, Rectangle, TextColor, BackColor, Text, Size ) ;
  410.   }
  411. }
  412.  
  413.  
  414. ULONG SpoolSize::NewValue ( void )
  415. {
  416.   ULONG PathSize ;
  417.   DosQuerySysInfo ( QSV_MAX_PATH_LENGTH, QSV_MAX_PATH_LENGTH, &PathSize, sizeof(PathSize) ) ;
  418.  
  419.   PBYTE Path = PBYTE ( malloc ( PathSize ) ) ;
  420.   if ( Path == NULL )
  421.   {
  422. //  Log ( "ERROR: Unable to allocate memory for spool-file search path.\r\n" ) ;
  423.     return ( 0 ) ;
  424.   }
  425.  
  426.   PFILEFINDBUF3 Found = PFILEFINDBUF3 ( malloc ( PathSize + sizeof(FILEFINDBUF3) ) ) ;
  427.   if ( Found == NULL )
  428.   {
  429. //  Log ( "ERROR: Unable to allocate memory for spool-file search result structure.\r\n" ) ;
  430.     free ( Path ) ;
  431.     return ( 0 ) ;
  432.   }
  433.  
  434.   strcpy ( (PCHAR)Path, (PCHAR)SpoolPath ) ;
  435.   strcat ( (PCHAR)Path, "\\*.*" ) ;
  436.  
  437.   HDIR hDir = (HDIR) HDIR_CREATE ;
  438.   ULONG Count = 1 ;
  439.   ULONG TotalSize = 0 ;
  440.  
  441.   if ( !DosFindFirst2 ( Path, &hDir,
  442.     FILE_NORMAL | FILE_READONLY | FILE_DIRECTORY | FILE_ARCHIVED,
  443.     Found, PathSize+sizeof(FILEFINDBUF3), &Count, FIL_STANDARD ) )
  444.   {
  445.  
  446.     do
  447.     {
  448.  
  449.       if ( !strcmp ( (PCHAR)Found->achName, "." )
  450.         OR !strcmp ( (PCHAR)Found->achName, ".." ) )
  451.       {
  452.         continue ;
  453.       }
  454.  
  455.       if ( Found->attrFile & FILE_DIRECTORY )
  456.       {
  457.         HDIR hDir = (HDIR) HDIR_CREATE ;
  458.  
  459.         strcpy ( (PCHAR)Path, (PCHAR)SpoolPath ) ;
  460.         strcat ( (PCHAR)Path, "\\" ) ;
  461.         strcat ( (PCHAR)Path, (PCHAR)Found->achName ) ;
  462.         strcat ( (PCHAR)Path, "\\*.*" ) ;
  463.  
  464.         Count = 1 ;
  465.         if ( !DosFindFirst2 ( Path, &hDir,
  466.           FILE_NORMAL | FILE_READONLY | FILE_ARCHIVED,
  467.           Found, PathSize+sizeof(FILEFINDBUF3), &Count, FIL_STANDARD ) )
  468.         {
  469.           do
  470.           {
  471.             TotalSize += Found->cbFileAlloc ;
  472.           }
  473.           while ( !DosFindNext ( hDir, Found, PathSize+sizeof(FILEFINDBUF3), &Count ) ) ;
  474.           DosFindClose ( hDir ) ;
  475.         }
  476.  
  477.         Count = 1 ;
  478.       }
  479.  
  480.       else
  481.       {
  482.         TotalSize += Found->cbFileAlloc ;
  483.       }
  484.     }
  485.     while ( !DosFindNext ( hDir, Found, PathSize+sizeof(FILEFINDBUF3), &Count ) ) ;
  486.  
  487.     DosFindClose ( hDir ) ;
  488.   }
  489.  
  490.   free ( Path ) ;
  491.   free ( Found ) ;
  492.  
  493.   return ( TotalSize ) ;
  494. }
  495.  
  496.  
  497. VOID SpoolSize::Repaint
  498. (
  499.   HPS hPS,
  500.   RECTL &Rectangle,
  501.   COLOR TextColor,
  502.   COLOR BackColor,
  503.   BOOL Mandatory
  504. )
  505. {
  506.   ULONG Size = NewValue ( ) ;
  507.  
  508.   if ( Mandatory || ( Size != Value ) )
  509.   {
  510.     BYTE Text [100] ;
  511.  
  512.     if ( Size < 0x80000 )
  513.       sprintf ( (PCHAR)Text, "%lu", Size ) ;
  514.     else
  515.       sprintf ( (PCHAR)Text, "%lu", (Size+512)/1024 ) ;
  516.  
  517.     {
  518.       PBYTE p1, p2 ;
  519.       BYTE Work[100] ;
  520.  
  521.       p1 = Text ;
  522.       p2 = Work ;
  523.       while ( *p1 )
  524.       {
  525.         *p2 = *p1 ;
  526.         p1 ++ ;
  527.         p2 ++ ;
  528.         if ( *p1 )
  529.         {
  530.           if ( strlen((PCHAR)p1) % 3 == 0 )
  531.           {
  532.             *p2 = CountryInfo.szThousandsSeparator [0] ;
  533.             p2 ++ ;
  534.           }
  535.         }
  536.       }
  537.       *p2 = 0 ;
  538.       strcpy ( (PCHAR)Text, (PCHAR)Work ) ;
  539.     }
  540.  
  541.     Text[strlen(PCHAR(Text))+1] = 0 ;
  542.     if ( Size < 0x80000 )
  543.       Text[strlen((PCHAR)Text)] = ' ' ;
  544.     else
  545.       Text[strlen((PCHAR)Text)] = 'K' ;
  546.  
  547.     Paint ( hPS, Rectangle, TextColor, BackColor, Text, Size ) ;
  548.   }
  549. }
  550.  
  551.  
  552. ULONG CpuLoad::NewValue ( void )
  553. {
  554.   MaxCount = (ULONG) max ( MaxCount, *IdleCount ) ;
  555.  
  556.   ULONG Load = ( ( MaxCount - *IdleCount ) * 100 ) / MaxCount ;
  557.  
  558.   return ( Load ) ;
  559. }
  560.  
  561.  
  562. VOID CpuLoad::Repaint
  563. (
  564.   HPS hPS,
  565.   RECTL &Rectangle,
  566.   COLOR TextColor,
  567.   COLOR BackColor,
  568.   BOOL Mandatory
  569. )
  570. {
  571.   ULONG Load = NewValue ( ) ;
  572.  
  573.   if ( Mandatory || ( Load != Value ) )
  574.   {
  575.     BYTE Text [100] ;
  576.     sprintf ( (PCHAR)Text, "%lu%%", Load ) ;
  577.     Paint ( hPS, Rectangle, TextColor, BackColor, Text, Load ) ;
  578.   }
  579. }
  580.  
  581.  
  582. ULONG TaskCount::NewValue ( void )
  583. {
  584.   return ( WinQuerySwitchList ( Anchor, PSWBLOCK(NULL), 0 ) ) ;
  585. }
  586.  
  587.  
  588. VOID TaskCount::Repaint
  589. (
  590.   HPS hPS,
  591.   RECTL &Rectangle,
  592.   COLOR TextColor,
  593.   COLOR BackColor,
  594.   BOOL Mandatory
  595. )
  596. {
  597.   ULONG Count = NewValue ( ) ;
  598.  
  599.   if ( Mandatory || ( Count != Value ) )
  600.   {
  601.     BYTE Text [100] ;
  602.     sprintf ( (PCHAR)Text, "%lu ", Count ) ;
  603.     Paint ( hPS, Rectangle, TextColor, BackColor, Text, Count ) ;
  604.   }
  605. }
  606.  
  607.  
  608. ULONG DriveFree::NewValue ( void )
  609. {
  610.   if ( Error )
  611.   {
  612.     return ( 0 ) ;
  613.   }
  614.  
  615.   DosError ( FERR_DISABLEHARDERR ) ;
  616.  
  617.   FSALLOCATE Allocation ;
  618.   USHORT Status = DosQueryFSInfo ( DriveNumber, FSIL_ALLOC, (PBYTE)&Allocation, sizeof(Allocation) ) ;
  619.  
  620.   DosError ( FERR_ENABLEHARDERR ) ;
  621.  
  622.   if ( Status )
  623.   {
  624.     Error = TRUE ;
  625.     return ( 0 ) ;
  626.   }
  627.  
  628.   return ( Allocation.cUnitAvail*Allocation.cSectorUnit*Allocation.cbSector ) ;
  629. }
  630.  
  631.  
  632. VOID DriveFree::Repaint
  633. (
  634.   HPS hPS,
  635.   RECTL &Rectangle,
  636.   COLOR TextColor,
  637.   COLOR BackColor,
  638.   BOOL Mandatory
  639. )
  640. {
  641.   ULONG Size = NewValue ( ) ;
  642.  
  643.   if ( Mandatory || ( Size != Value ) )
  644.   {
  645.     BYTE Text [100] ;
  646.  
  647.     if ( Error )
  648.     {
  649.       strcpy ( PCHAR(Text), PCHAR(DriveError) ) ;
  650.     }
  651.     else
  652.     {
  653.       if ( Size < 0x80000 )
  654.         sprintf ( (PCHAR)Text, "%lu", Size ) ;
  655.       else
  656.         sprintf ( (PCHAR)Text, "%lu", (Size+512)/1024 ) ;
  657.  
  658.       {
  659.         PBYTE p1, p2 ;
  660.         BYTE Work[100] ;
  661.  
  662.         p1 = Text ;
  663.         p2 = Work ;
  664.         while ( *p1 )
  665.         {
  666.           *p2 = *p1 ;
  667.           p1 ++ ;
  668.           p2 ++ ;
  669.           if ( *p1 )
  670.           {
  671.             if ( strlen((PCHAR)p1) % 3 == 0 )
  672.             {
  673.               *p2 = CountryInfo.szThousandsSeparator [0] ;
  674.               p2 ++ ;
  675.             }
  676.           }
  677.         }
  678.         *p2 = 0 ;
  679.         strcpy ( (PCHAR)Text, (PCHAR)Work ) ;
  680.       }
  681.  
  682.       Text[strlen(PCHAR(Text))+1] = 0 ;
  683.       if ( Size < 0x80000 )
  684.         Text[strlen((PCHAR)Text)] = ' ' ;
  685.       else
  686.         Text[strlen((PCHAR)Text)] = 'K' ;
  687.     }
  688.  
  689.     Paint ( hPS, Rectangle, TextColor, BackColor, Text, Size ) ;
  690.   }
  691. }
  692.  
  693.  
  694. ULONG TotalFree::NewValue ( void )
  695. {
  696.   ULONG Free = 0 ;
  697.   ULONG Mask = Drives >> 2 ;
  698.  
  699.   for ( int Drive=3; Drive<=26; Drive++ )
  700.   {
  701.     if ( Mask & 1 )
  702.     {
  703.       DosError ( FERR_DISABLEHARDERR ) ;
  704.  
  705.       FSALLOCATE Allocation ;
  706.       USHORT Status = DosQueryFSInfo ( Drive, FSIL_ALLOC, (PBYTE)&Allocation, sizeof(Allocation) ) ;
  707.  
  708.       DosError ( FERR_ENABLEHARDERR ) ;
  709.  
  710.       if ( Status )
  711.       {
  712.         Drives &= ~ ( 1 << (Drive-1) ) ;
  713.       }
  714.       else
  715.       {
  716.         Free += Allocation.cUnitAvail*Allocation.cSectorUnit*Allocation.cbSector ;
  717.       }
  718.     }
  719.     Mask >>= 1 ;
  720.   }
  721.  
  722.   return ( Free ) ;
  723. }
  724.  
  725.  
  726. VOID TotalFree::Repaint
  727. (
  728.   HPS hPS,
  729.   RECTL &Rectangle,
  730.   COLOR TextColor,
  731.   COLOR BackColor,
  732.   BOOL Mandatory
  733. )
  734. {
  735.   ULONG Size = NewValue ( ) ;
  736.  
  737.   if ( Mandatory || ( Size != Value ) )
  738.   {
  739.     BYTE Text [100] ;
  740.  
  741.     if ( Size < 0x80000 )
  742.       sprintf ( (PCHAR)Text, "%lu", Size ) ;
  743.     else
  744.       sprintf ( (PCHAR)Text, "%lu", (Size+512)/1024 ) ;
  745.  
  746.     {
  747.       PBYTE p1, p2 ;
  748.       BYTE Work[100] ;
  749.  
  750.       p1 = Text ;
  751.       p2 = Work ;
  752.       while ( *p1 )
  753.       {
  754.         *p2 = *p1 ;
  755.         p1 ++ ;
  756.         p2 ++ ;
  757.         if ( *p1 )
  758.         {
  759.           if ( strlen((PCHAR)p1) % 3 == 0 )
  760.           {
  761.             *p2 = CountryInfo.szThousandsSeparator [0] ;
  762.             p2 ++ ;
  763.           }
  764.         }
  765.       }
  766.       *p2 = 0 ;
  767.       strcpy ( (PCHAR)Text, (PCHAR)Work ) ;
  768.     }
  769.  
  770.     Text[strlen(PCHAR(Text))+1] = 0 ;
  771.     if ( Size < 0x80000 )
  772.       Text[strlen((PCHAR)Text)] = ' ' ;
  773.     else
  774.       Text[strlen((PCHAR)Text)] = 'K' ;
  775.  
  776.     Paint ( hPS, Rectangle, TextColor, BackColor, Text, Size ) ;
  777.   }
  778. }
  779.